package com.lmf.cmsservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lmf.cmsservice.entity.CrmBanner;
import com.lmf.cmsservice.entity.vo.BannerQuery;
import com.lmf.cmsservice.mapper.CrmBannerMapper;
import com.lmf.cmsservice.service.CrmBannerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author lmf
 * @since 2022-02-01
 */
@Service
public class CrmBannerServiceImpl extends ServiceImpl<CrmBannerMapper, CrmBanner> implements CrmBannerService {

    @Override
    public List<CrmBanner> pageQuery(Page<CrmBanner> bannerPage, BannerQuery bannerQuery) {
        return null;
    }

    //获取所有幻灯片
    @Cacheable(value = "banner",key = "'selectIndexList'")
    @Override
    public List<CrmBanner> getAllBanner() {
        //只查出前两条，且按照id降序排列
        QueryWrapper<CrmBanner> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        wrapper.last("limit 2");
        //但没有实际运用，还是查出全部幻灯片
        List<CrmBanner> list = this.list(null);
        return list;
    }
}
